<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/15 0015
 * Time: 23:39
 */
include 'ubm.php';

//面向对象与面向过程代码比较
class Adder
{
    function add2($a, $b)
    {
        return $a + $b;
    }

    function add3($a, $b, $c)
    {
        return $a + $b;
    }
}

function add2($a, $b)
{
    return $a + $b;
}

function add3($a, $b, $c)
{
    return $a + $b;
}

function run_oo_bm2($count)
{
    $adder = new Adder();
    for ($i = 0; $i < $count; $i++) {
        $adder->add2(5, 7);
    }
}

function run_oo_bm3($count)
{
    $adder = new Adder();
    for ($i = 0; $i < $count; $i++) {
        $adder->add3(5, 7, 9);
    }
}

function run_proc_bm2($count)
{
    for ($i = 0; $i < $count; $i++) {
        add2(5, 7);
    }
}

function run_proc_bm3($count)
{
    for ($i = 0; $i < $count; $i++) {
        add3(5, 7, 9);
    }
}

$loops = 1000;
micro_benchmark('proc_2_agrs', 'run_proc_bm2', $loops);
micro_benchmark('proc_3_agrs', 'run_proc_bm3', $loops);
micro_benchmark('oo_2_agrs', 'run_oo_bm2', $loops);
micro_benchmark('oo_3_agrs', 'run_oo_bm3', $loops);